package com.monkeygroup.mygoplus.ecchat.ui.contact.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.monkeygroup.mygoplus.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/13.
 */
public class SearchRecordAdapter extends BaseAdapter {
    private List<Map<String, Object>> itemData;
    private Context mContext;
    private LayoutInflater inflater;

    public SearchRecordAdapter(Context context, List<Map<String, Object>> data) {
        mContext = context;
        itemData = data;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (itemData != null) {
            return itemData.size();
        }

        return 0;
    }

    @Override
    public Map<String, Object> getItem(int position) {
        if (itemData != null) {
            return itemData.get(position);
        }

        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_simple_listview, null);
            holder = new ViewHolder();
            holder.record_icon = (ImageView) convertView.findViewById(R.id.item_icon);
            holder.record_content = (TextView) convertView.findViewById(R.id.item_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Map<String, Object> info = itemData.get(position);
        holder.record_content.setText((String) info.get("content"));
        holder.record_icon.setVisibility(View.GONE);

        return convertView;
    }

    private class ViewHolder {
        ImageView record_icon;
        TextView record_content;
    }

}
